<#include "${ftl_skin}/common/header.ftl">
</head>
<body class="gray-bg">
<div class="row wrapper wrapper-content animated fadeInRight">
  <div class="col-sm-12">
    <div class="ibox float-e-margins">
      <div class="ibox-title">
        <h5>功能权限配置</h5>
        <div class="ibox-tools">
            <button class="btn btn-primary m-r-xl" onclick="addTop()" type="button">添加</button>
            <a href="javascript:void(0);" class="open-all"> <i class="fa fa-plus">全部展开</i> </a>
            <a href="javascript:void(0);" class="close-all"> <i class="fa fa-minus">全部收起</i> </a>
        </div>
      </div>
      <div class="ibox-content">
        <div id="treeview1" class="test"></div>
      </div>
    </div>
  </div>
</div>
<#include "${ftl_skin}/common/js.ftl">
<script src="${path.skinPath }js/demo/layer-demo.min.js"></script> 
<script src="${path.skinPath }js/plugins/treeview/bootstrap-treeview.js"></script> 
<script src="${path.skinPath }js/plugins/sweetalert/sweetalert.min.js"></script> 
<script>
	$(function() {
        initDialogPanel();

		var treeData = getTreeData();
		$("#treeview1").treeview({
			data: treeData,
			showTags: !0,
			showBottons: !0
		});
		$(".open-all").click(function () {
			$("#treeview1").treeview({
				data: treeData,
				levels: 99,
				showTags: !0,
				showBottons: !0
			});
		});
			
		$(".close-all").click(function () {
			$("#treeview1").treeview({
				data: treeData,
				levels: 1,
				showTags: !0,
				showBottons: !0
			});
		});
	});
	
	function getTreeData(){
		var treeList,treeData;
		
		$.ajax({
            url: "${path.servicePath}/func/treelist.do",
            async: false,
            type: 'POST',
            data: {parent_tree_code:'${parentSeqCode}'},
            complete:function(XMLHttpRequest, textStatus){
//                 alert(XMLHttpRequest.responseText);
            },
            success: function(data){
                if(data.state == 0){
                   treeList = data.result;
				  
                }
            }
        });
		
/*		var treeList = [{"id":"001","text":"父节点 1","pid":"-1"},{"id":"002","text":"父节点 2","pid":"-1"},{"id":"001001","text":"子节点 1","pid":"001"},{"id":"001002","text":"子节点 2","pid":"001"},{"id":"001001001","text":"孙节点 1","pid":"001001"},{"id":"001001002","text":"孙节点 2","pid":"001001"}];*/
		//alert(treeList.length);
		
		if(treeList.length>0){
			for(var i = 0 ; i < treeList.length ; i++){
				//alert(treeList[i].IS_OPEN);
				
				// if(i==0){
				// 	treeList[i].bottons= ["plus-square-o"];
				// 	continue;
				// }
				
				if(treeList[i].IS_OPEN==1){
					treeList[i].bottons= ["trash", "plus-square-o", "edit"];
				}else{
					treeList[i].bottons= ["trash", "plus-square-o", "edit"];
				}
				
			}
			
			treeData = toTree(treeList,"-1");
		}
		
		return treeData;
	}
	
	function tree_botton_bind(){
	
		$("#treeview1 .tree-btn.trash").click(function () {
			var tree_code = $(this).parents("li").attr("data-treeid");
			
			swal({
				title: "您确定要删除这条信息吗",
				text: "删除后将无法恢复，请谨慎操作！",
				type: "warning",
				showCancelButton: true,
				confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
				closeOnConfirm: false
			}, function () {
				//删除操作;
				//alert("执行删除操作");

				$.ajax({
		            url: "${path.servicePath}/func/tnodedel.do",
		            async: false,
		            type: 'POST',
		            data: {treeCode:tree_code},
		            complete:function(XMLHttpRequest, textStatus){
		//                 alert(XMLHttpRequest.responseText);
		            },
		            success: function(data){
		                location.reload();
		            }
	       		 });
			
				
				
			});
		});
		
		
		$("#treeview1 .tree-btn.plus-square-o").click(function () {
			var tree_code = $(this).parents("li").attr("data-treeid");
			openDialog('tnodeadd', '功能添加', '${path.viewPath }func/tnodeadd.do?parentTreeCode=' + tree_code, '', 800, 280, function(){
         	//刷新页面
         		if("reload"==this.returnValue){
         			location.reload();
         		}
         		
			});
		});
		
		
		$("#treeview1 .tree-btn.edit").click(function () {
		var tree_code = $(this).parents("li").attr("data-treeid");
			openDialog('tnodeedit', '功能编辑', '${path.viewPath }func/tnodeedit.do?treeCode=' + tree_code, '', 800, 280, function(){
	     		//刷新页面
				if("reload"==this.returnValue){
         			location.reload();
         		}
	     	});
        });

		/*	n=parent.layer.prompt({
				type: 2,
				title: '标题',
				closeBtn: !0,
				shadeClose: true,
				shade: 0.8,
				area: ['580px', '90%'],
				content: 'tree_view.html' //iframe的url
			});*/
			//parent.layer.close(n);
		
		
		
	}

    function addTop(){
        openDialog('tnodeadd', '功能添加', '${path.viewPath }func/tnodeadd.do?', '', 800, 280, function(){
            //刷新页面
            if("reload"==this.returnValue){
                location.reload();
            }

        });
    }


    function toTree(data, pid) {
        var result = [], temp;
        for (var i = 0; i < data.length; i++) {
            if (data[i].parent_tree_code == pid) {
                var obj = data[i];
                obj.id = data[i].tree_code;
                obj.text = data[i].node_name;
                temp = toTree(data, data[i].tree_code);
                if (temp.length > 0) {
                    obj.nodes = temp;
                }

                result.push(obj);
            }
        }

        return result;
    }
</script>
<#include "${ftl_skin}/common/footer.ftl">
